//
//  UserLikeThingViewController.m
//  one·一个  tyw
//
//  Created by tyw on 15/9/16.
//  Copyright (c) 2015年 tyw. All rights reserved.
//

#import "UserLikeThingViewController.h"
#import "ThingTableView.h"
#import "DataService.h"

@interface UserLikeThingViewController ()

@end

@implementation UserLikeThingViewController {
    ThingTableView* _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self _createNavBar];
    [self _createTableView];
}

- (void)viewWillAppear:(BOOL)animated {
    self.navigationController.navigationBar.hidden = NO;
    [_tableView setContentOffset:CGPointMake(0, navBarHeight)];            //在这里写这一句，可以在每次打开新的页面时，让它从最头部开始
}

- (void)_createNavBar {
    UIBarButtonItem* shareBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"shareBtn"] style:UIBarButtonItemStylePlain target:self action:@selector(cancelLikeAction)];
    self.navigationItem.rightBarButtonItem = shareBtn;
}

- (void)cancelLikeAction {
    UIActionSheet* cancelLikeSheet = [[UIActionSheet alloc] initWithTitle:@"取消收藏" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [cancelLikeSheet showInView:self.view];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {         //确定
        NSLog(@"确定   取消收藏");
        
        
        NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
        [params setObject:kStrUi forKey:@"strUi"];
        [params setObject:_dataDic[@"strId"] forKey:@"strCi"];
        [params setObject:@3 forKey:@"strCt"];
        [params setObject:@-1 forKey:@"strQi"];
        [params setObject:@0 forKey:@"strBr"];
        [params setObject:@0 forKey:@"strRtype"];
        
        [DataService oneRequestUrl:kHomeCollectUrl httpMethod:@"POST" params:params block:^(id result) {
            if ([result isKindOfClass:[NSError class]]) {
                NSLog(@"网络请求 东西页 取消收藏失败  %@", result);
            }
            
            NSLog(@"网络请求 东西页 取消收藏成功");
            
            [self.navigationController popViewControllerAnimated:YES];
        }];
        
    } else {                    //取消
        NSLog(@"取消");
    }
}

- (void)_createTableView {
    _tableView = [[ThingTableView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
    _tableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_tableView];
    
    
    
    //网络请求获得数据
    //01 构造参数
    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
    [params setObject:_dataDic[@"strD"] forKey:@"strDate"];
    [params setObject:@1 forKey:@"strRow"];
    
    //网络请求
    [DataService oneRequestUrl:kThingUrl httpMethod:@"GET" params:params block:^(id result) {
        if ([result isKindOfClass:[NSError class]]) {
            NSLog(@"东西页收藏详情查看失败  %@", result);
        }
        
        //设置参数
        _tableView.dataDic = result[@"entTg"];
    }];
}

@end
